import 'package:flutter_app1/model/common_model.dart';
import 'package:flutter_app1/model/config_model.dart';
import 'package:flutter_app1/model/grid_nav_model.dart';
import 'package:flutter_app1/model/sales_box_model.dart';

class HomeModel {
  final ConfigModel config;
  final List<CommonModel> bannerList;
  final List<CommonModel> localNavList;
  final List<CommonModel> subNavList;
  final GridNavModel gridNav;// 网格导航
  final SalesBoxModel salesBox;// 活动入口模型

  HomeModel({
    required this.config,
    required this.bannerList,
    required this.localNavList,
    required this.subNavList,
    required this.gridNav,
    required this.salesBox
  });

  factory HomeModel.fromJson(Map<String, dynamic> json) {
    // 本地导航列表
    var localNavListJson = json['localNavList'] as List;
    List<CommonModel> localNavList = localNavListJson.map((i) => CommonModel.fromJson(i)).toList();
    print("localNavList"+json['localNavList'].toString());
    for (CommonModel localNav in localNavList) {
      print(localNav.toJson());
    }

    // 轮播图列表
    var bannerListJson = json['bannerList'] as List;
    List<CommonModel> bannerList = bannerListJson.map((i) => CommonModel.fromJson(i)).toList();
    print("bannerList"+json['bannerList'].toString());
    for (CommonModel localNav in bannerList) {
      print(localNav.toJson());
    }

    // 子导航列表
    var subNavListJson = json['subNavList'] as List;
    List<CommonModel> subNavList = subNavListJson.map((i) => CommonModel.fromJson(i)).toList();
    print("subNavList");
    for (CommonModel localNav in subNavList) {
      print(localNav.toJson());
    }

    return HomeModel(
      localNavList: localNavList,
      bannerList: bannerList,
      subNavList: subNavList,
      config: ConfigModel.fromJson(json['config']),
      gridNav: GridNavModel.fromJson(json['gridNav']),
      salesBox: SalesBoxModel.fromJson(json['salesBox']),
    );
  }
}
